package com.ggy.babybed.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;

import java.io.FileDescriptor;
import java.io.PrintWriter;

/**
 * Created by sizi on 2016/5/19.
 */
public abstract class ObserveNodeService extends Service{

    public static final String TAG="ObserveNodeService";

    private Handler mHandler;
    private boolean mMessageNode=false;
    private boolean mTempNode=false;
    private boolean mShiduNode=false;

    @Override
    public IBinder onBind(Intent intent) {
        return new ServiceBinder();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        return super.onUnbind(intent);
    }

    public class ServiceBinder extends Binder implements ServiceCommand{
        public ObserveNodeService getService(){
            return ObserveNodeService.this;
        }

        @Override
        public void stopMessageNode() {
            if(mMessageNode==false){
                return;
            }
            mMessageNode=false;
            setMessageNode(false);
        }

        public void startMessageNode(){
            if(mMessageNode==true){
                return;
            }
            mMessageNode=true;
            setMessageNode(true);
        }

        @Override
        public void startTempNode() {
            if(mTempNode==true){
                return;
            }
            mTempNode=true;
            setTempNode(true);
        }

        @Override
        public void stopTempNode() {
            if(mTempNode==false){
                return;
            }
            mTempNode=false;
            setTempNode(false);
        }

        @Override
        public void startShiduNode() {
            if(mShiduNode==true){
                return;
            }
            mShiduNode=true;
            setShiduNode(true);
        }

        @Override
        public void stopShiduNode() {
            if(mShiduNode==false){
                return;
            }
            mShiduNode=false;
            setShiduNode(false);
        }

        public void setHandler(Handler handler){
            mHandler=handler;
        }

        public void startAll(){
            startMessageNode();
            startShiduNode();
            startTempNode();
        }

        public void stopAll(){
            stopMessageNode();
            stopShiduNode();
            stopTempNode();
        }
    }

    public abstract void setMessageNode(boolean status);

    public abstract void setTempNode(boolean status);

    public abstract void setShiduNode(boolean status);

    @Override
    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        super.dump(fd, writer, args);
        writer.print("mMessageNode : "+mMessageNode);
        writer.print("mShiduNode : "+mShiduNode);
        writer.print("mMessageNode"+mMessageNode);
    }

}
